<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>乐高积木与Java对象的奇妙对应 | 技术小馆</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        :root {
            --primary: #2563eb;
            --primary-light: #3b82f6;
            --secondary: #7c3aed;
            --accent: #10b981;
            --dark: #1e293b;
            --light: #f8fafc;
        }
        body {
            font-family: 'Noto Sans SC', 'Helvetica Neue', Arial, sans-serif;
            color: #334155;
            line-height: 1.6;
            background-color: #f8fafc;
        }
        h1, h2, h3, h4, h5, h6 {
            font-family: 'Noto Serif SC', Georgia, serif;
            font-weight: 700;
            color: var(--dark);
        }
        .hero {
            background: linear-gradient(135deg, rgba(37, 99, 235, 0.8) 0%, rgba(124, 58, 237, 0.8) 100%);
        }
        .card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .code-block {
            background-color: #1e293b;
            border-left: 4px solid var(--accent);
        }
        .table-container {
            overflow-x: auto;
        }
        table {
            min-width: 100%;
        }
        th {
            background-color: var(--primary);
            color: white;
        }
        tr:nth-child(even) {
            background-color: #f1f5f9;
        }
        .mermaid {
            background-color: white;
            padding: 1.5rem;
            border-radius: 0.5rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
        .footer {
            background-color: var(--dark);
        }
        .footer a:hover {
            color: var(--primary-light);
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <section class="hero text-white py-20 px-4 md:px-8">
        <div class="max-w-6xl mx-auto">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold leading-tight mb-4">乐高积木与Java对象的奇妙对应</h1>
                    <p class="text-xl mb-6">探索面向对象编程与乐高积木之间的惊人相似之处</p>
                    <div class="flex items-center space-x-4">
                        <span class="inline-flex items-center px-3 py-1 rounded-full bg-white bg-opacity-20">
                            <i class="fas fa-cube mr-2"></i> 面向对象
                        </span>
                        <span class="inline-flex items-center px-3 py-1 rounded-full bg-white bg-opacity-20">
                            <i class="fas fa-puzzle-piece mr-2"></i> 设计模式
                        </span>
                    </div>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <img src="https://cdn.nlark.com/yuque/0/2025/png/21449790/1741062937218-e734c27e-c59c-42e8-9c6e-a4c839bff9cb.png" 
                         alt="乐高积木与Java对象对应关系" 
                         class="rounded-lg shadow-xl w-full max-w-md">
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto py-12 px-4 md:px-8">
        <!-- Introduction -->
        <section class="mb-16">
            <div class="prose max-w-none lg:prose-xl">
                <p class="text-lg leading-relaxed">
                    每个乐高积木都是一个小小的 Java 对象。每个积木都有自己的颜色、形状和连接方式，就像 Java 对象有自己的属性（字段）和行为（方法）。当我们把这些积木按照一定的规则组合在一起时，就构建出了一个精美的乐高模型，这就类似于我们用面向对象的思维将多个对象组合成一个完整的系统。
                </p>
            </div>
        </section>

        <!-- Section 1 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 border-b-2 border-primary pb-2">一、乐高积木与Java对象的奇妙对应</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-10">
                <div class="card bg-white p-6 rounded-lg shadow-md">
                    <h3 class="text-2xl font-bold mb-4 text-primary flex items-center">
                        <i class="fas fa-shapes mr-3"></i> 1.1 类与对象的类比
                    </h3>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-cube text-secondary mr-2 mt-1"></i>
                            <span><strong>类</strong>：在 Java 中，类定义了一种对象的模板，描述了对象应该有哪些属性和行为。类似地，在乐高世界中，我们可以把"乐高积木"定义为一种模板，描述了积木的形状、颜色、尺寸和如何与其他积木连接。</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-box-open text-secondary mr-2 mt-1"></i>
                            <span><strong>对象</strong>：通过类实例化出来的对象，就像乐高积木工厂生产出的单个积木。每个乐高积木都是一个具体的实例，它们可以有不同的颜色或者细节，但都遵循同样的连接规则。</span>
                        </li>
                    </ul>
                </div>
                
                <div class="card bg-white p-6 rounded-lg shadow-md">
                    <h3 class="text-2xl font-bold mb-4 text-primary flex items-center">
                        <i class="fas fa-lock mr-3"></i> 1.2 封装与模块化
                    </h3>
                    <p>乐高积木设计精妙之处在于每一块积木都能独立存在，带有标准化的连接口。这样，你可以随心所欲地拼接、拆卸、重构，而不必关心内部构造。</p>
                    <p class="mt-3">Java 中的封装正是这种思想——将数据和方法包装在一个对象内部，并通过公开的接口与外部进行交互，保证对象内部的实现细节不被外部直接干扰。</p>
                    <div class="bg-blue-50 p-4 rounded-md mt-4 border-l-4 border-blue-500">
                        <p class="text-sm italic">例如，一个乐高"车轮"积木，只需要知道如何和车身连接，而不必了解车轮内部的材料构造，同理，一个 Java 对象对外提供公共方法，但内部数据可以被隐藏和保护。</p>
                    </div>
                </div>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <div class="card bg-white p-6 rounded-lg shadow-md">
                    <h3 class="text-2xl font-bold mb-4 text-primary flex items-center">
                        <i class="fas fa-project-diagram mr-3"></i> 1.3 继承与多态：乐高积木的扩展性
                    </h3>
                    <p>设想你有一套基本的乐高积木，可以拼出各种模型。如果你想构建更复杂的模型，可能会设计出"高级版"的积木，增加一些特殊的功能，比如发光或可转动。</p>
                    <p class="mt-3">Java 中的继承和多态就像是这种扩展性：你可以在已有类的基础上派生出子类，添加新的属性和方法，同时子类对象可以替代父类对象出现在任何需要父类的地方，实现了代码复用和灵活扩展。</p>
                </div>
                
                <div class="card bg-white p-6 rounded-lg shadow-md">
                    <h3 class="text-2xl font-bold mb-4 text-primary flex items-center">
                        <i class="fas fa-puzzle-piece mr-3"></i> 1.4 组合：乐高积木拼装整体
                    </h3>
                    <p>在乐高模型中，单块积木本身可能很简单，但当你将它们按照预定的设计图组合在一起，就能构成复杂的建筑或机器。</p>
                    <p class="mt-3">同样，在面向对象编程中，我们经常使用<strong>组合</strong>的方式，将多个对象组合成一个更复杂的系统。每个对象负责自己的功能，而整个系统则通过对象之间的合作来完成复杂的任务。这种"积木拼装"式的设计，让我们的系统既具有高度的模块化，又便于维护和扩展。</p>
                </div>
            </div>
        </section>

        <!-- Section 2 -->
        <section class="mb-16">
            <div class="flex flex-col md:flex-row items-center mb-10">
                <div class="md:w-1/2 mb-6 md:mb-0">
                    <h2 class="text-3xl font-bold mb-6 border-b-2 border-primary pb-2">二、面向对象四大核心思想</h2>
                    <p class="text-lg">面向对象编程的核心思想就像乐高积木的设计哲学，它们共同构建了强大而灵活的软件系统。</p>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <img src="https://cdn.nlark.com/yuque/0/2025/png/21449790/1741063021949-9de9c1fe-8957-4afa-a5e8-4e41ab282d53.png" 
                         alt="面向对象四大核心思想" 
                         class="rounded-lg shadow-md w-full max-w-md">
                </div>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <div class="card bg-white p-6 rounded-lg shadow-md">
                    <h3 class="text-2xl font-bold mb-4 text-primary flex items-center">
                        <i class="fas fa-lock mr-3"></i> 2.1 封装：保险箱的安全哲学
                    </h3>
                    <div class="code-block text-gray-200 p-4 rounded-md mb-4 overflow-x-auto">
                        <pre><code>// 银行账户封装示例
public class BankAccount {
    private String owner;    // 封装属性
    private double balance;
    
    // 封装方法
    public void deposit(double amount) {
        if(amount > 0) balance += amount;
    }
    
    public double getBalance() {
        return balance;
    }
}</code></pre>
                    </div>
                    <p><strong>设计优势</strong>：隐藏实现细节，暴露安全接口，如同ATM机只开放插卡口和出钞口。</p>
                </div>
                
                <div class="card bg-white p-6 rounded-lg shadow-md">
                    <h3 class="text-2xl font-bold mb-4 text-primary flex items-center">
                        <i class="fas fa-arrow-up-from-bracket mr-3"></i> 2.2 继承：家族基因的传承
                    </h3>
                    <div class="code-block text-gray-200 p-4 rounded-md mb-4 overflow-x-auto">
                        <pre><code>// 支付方式继承体系
public abstract class Payment {
    public abstract void pay(double amount);
}

public class Alipay extends Payment {
    @Override
    public void pay(double amount) {
        // 调用支付宝SDK
    }
}</code></pre>
                    </div>
                </div>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mt-8">
                <div class="card bg-white p-6 rounded-lg shadow-md">
                    <h3 class="text-2xl font-bold mb-4 text-primary flex items-center">
                        <i class="fas fa-exchange-alt mr-3"></i> 2.3 多态：万能遥控器的智慧
                    </h3>
                    <div class="code-block text-gray-200 p-4 rounded-md mb-4 overflow-x-auto">
                        <pre><code>// 多态应用示例
public class PaymentProcessor {
    public void processPayment(Payment payment, double amount) {
        payment.pay(amount); // 自动适配具体实现
    }
}</code></pre>
                    </div>
                </div>
                
                <div class="card bg-white p-6 rounded-lg shadow-md">
                    <h3 class="text-2xl font-bold mb-4 text-primary flex items-center">
                        <i class="fas fa-drafting-compass mr-3"></i> 2.4 抽象：设计图纸的智慧
                    </h3>
                    <div class="code-block text-gray-200 p-4 rounded-md mb-4 overflow-x-auto">
                        <pre><code>// 抽象工厂模式
public interface VehicleFactory {
    Engine createEngine();
    Wheel createWheel();
}

public class CarFactory implements VehicleFactory {
    // 具体实现
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Section 3 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 border-b-2 border-primary pb-2">三、六大设计原则（SOLID+）</h2>
            
            <div class="table-container bg-white rounded-lg shadow-md overflow-hidden mb-8">
                <table class="w-full">
                    <thead>
                        <tr>
                            <th class="py-3 px-4 text-left">原则</th>
                            <th class="py-3 px-4 text-left">名称</th>
                            <th class="py-3 px-4 text-left">通俗解释</th>
                            <th class="py-3 px-4 text-left">代码示例</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td class="py-3 px-4 border-b border-gray-200">SRP</td>
                            <td class="py-3 px-4 border-b border-gray-200">单一职责</td>
                            <td class="py-3 px-4 border-b border-gray-200">一个类只做一件事</td>
                            <td class="py-3 px-4 border-b border-gray-200">订单类不处理支付逻辑</td>
                        </tr>
                        <tr>
                            <td class="py-3 px-4 border-b border-gray-200">OCP</td>
                            <td class="py-3 px-4 border-b border-gray-200">开闭原则</td>
                            <td class="py-3 px-4 border-b border-gray-200">对扩展开放，对修改关闭</td>
                            <td class="py-3 px-4 border-b border-gray-200">使用策略模式扩展支付方式</td>
                        </tr>
                        <tr>
                            <td class="py-3 px-4 border-b border-gray-200">LSP</td>
                            <td class="py-3 px-4 border-b border-gray-200">里氏替换</td>
                            <td class="py-3 px-4 border-b border-gray-200">子类可无缝替换父类</td>
                            <td class="py-3 px-4 border-b border-gray-200">正方形继承自矩形需谨慎</td>
                        </tr>
                        <tr>
                            <td class="py-3 px-4 border-b border-gray-200">ISP</td>
                            <td class="py-3 px-4 border-b border-gray-200">接口隔离</td>
                            <td class="py-3 px-4 border-b border-gray-200">接口要小而专</td>
                            <td class="py-3 px-4 border-b border-gray-200">拆分多功能接口为多个专用接口</td>
                        </tr>
                        <tr>
                            <td class="py-3 px-4 border-b border-gray-200">DIP</td>
                            <td class="py-3 px-4 border-b border-gray-200">依赖倒置</td>
                            <td class="py-3 px-4 border-b border-gray-200">依赖抽象而非实现</td>
                            <td class="py-3 px-4 border-b border-gray-200">通过接口调用服务而非具体类</td>
                        </tr>
                        <tr>
                            <td class="py-3 px-4">CARP</td>
                            <td class="py-3 px-4">组合优于继承</td>
                            <td class="py-3 px-4">优先使用组合扩展功能</td>
                            <td class="py-3 px-4">用装饰器模式替代多层继承</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <div class="mermaid">
                graph TD
                    A[面向对象原则] --> B[SOLID]
                    B --> B1[单一职责]
                    B --> B2[开闭原则]
                    B --> B3[里氏替换]
                    B --> B4[接口隔离]
                    B --> B5[依赖倒置]
                    A --> C[其他重要原则]
                    C --> C1[组合优于继承]
                    C --> C2[迪米特法则]
                    C --> C3[最少知识原则]
            </div>
        </section>

        <!-- Section 4 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 border-b-2 border-primary pb-2">四、实战案例一：电商订单系统</h2>
            
            <div class="mb-8">
                <h3 class="text-2xl font-bold mb-4 text-primary flex items-center">
                    <i class="fas fa-shopping-cart mr-3"></i> 4.1 需求场景
                </h3>
                <ul class="list-disc pl-6 space-y-2">
                    <li>支持多种订单类型（普通/秒杀/团购）</li>
                    <li>动态计算价格</li>
                    <li>灵活扩展促销策略</li>
                </ul>
            </div>
            
            <div class="mb-8">
                <h3 class="text-2xl font-bold mb-4 text-primary flex items-center">
                    <i class="fas fa-project-diagram mr-3"></i> 4.2 精妙架构设计
                </h3>
                <div class="code-block text-gray-200 p-4 rounded-md mb-4 overflow-x-auto">
                    <pre><code>// 策略模式实现价格计算
public interface PricingStrategy {
    double calculate(Order order);
}

public class NormalPricing implements PricingStrategy {
    public double calculate(Order order) {
        return order.getTotal() * 0.98; // 普通订单98折
    }
}

public class SeckillPricing implements PricingStrategy {
    public double calculate(Order order) {
        return order.getTotal() * 0.5; // 秒杀订单5折
    }
}

// 订单处理器
public class OrderProcessor {
    private PricingStrategy strategy;
    
    public OrderProcessor(PricingStrategy strategy) {
        this.strategy = strategy;
    }
    
    public void process(Order order) {
        double finalPrice = strategy.calculate(order);
        // 处理订单逻辑
    }
}</code></pre>
                </div>
            </div>
            
            <div>
                <h3 class="text-2xl font-bold mb-4 text-primary flex items-center">
                    <i class="fas fa-star mr-3"></i> 4.3 架构优势
                </h3>
                <div class="grid md:grid-cols-3 gap-4">
                    <div class="bg-blue-50 p-4 rounded-md border-l-4 border-blue-500">
                        <h4 class="font-bold mb-2">扩展性</h4>
                        <p>新增促销策略只需实现接口</p>
                    </div>
                    <div class="bg-green-50 p-4 rounded-md border-l-4 border-green-500">
                        <h4 class="font-bold mb-2">可维护性</h4>
                        <p>各策略独立修改互不影响</p>
                    </div>
                    <div class="bg-purple-50 p-4 rounded-md border-l-4 border-purple-500">
                        <h4 class="font-bold mb-2">灵活性</h4>
                        <p>运行时动态切换策略</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Section 5 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 border-b-2 border-primary pb-2">五、实战案例二：分布式支付系统</h2>
            
            <div class="mb-8">
                <h3 class="text-2xl font-bold mb-4 text-primary flex items-center">
                    <i class="fas fa-money-bill-wave mr-3"></i> 5.1 挑战难点
                </h3>
                <ul class="list-disc pl-6 space-y-2">
                    <li>多支付渠道（支付宝/微信/银联）</li>
                    <li>统一异常处理</li>
                    <li>交易流水追踪</li>
                </ul>
            </div>
            
            <div class="mb-8">
                <h3 class="text-2xl font-bold mb-4 text-primary flex items-center">
                    <i class="fas fa-network-wired mr-3"></i> 5.2 精妙架构设计
                </h3>
                <div class="code-block text-gray-200 p-4 rounded-md mb-4 overflow-x-auto">
                    <pre><code>// 责任链模式实现支付路由
public abstract class PaymentHandler {
    protected PaymentHandler next;
    
    public void setNext(PaymentHandler next) {
        this.next = next;
    }
    
    public abstract void handle(PaymentRequest request);
}

public class AlipayHandler extends PaymentHandler {
    public void handle(PaymentRequest request) {
        if(supportAlipay(request)) {
            // 处理支付宝支付
        } else if(next != null) {
            next.handle(request);
        }
    }
}

// 建造者模式创建复杂支付请求
public class PaymentRequestBuilder {
    private String orderId;
    private BigDecimal amount;
    
    public PaymentRequestBuilder setOrderId(String orderId) {
        this.orderId = orderId;
        return this;
    }
    
    public PaymentRequest build() {
        return new PaymentRequest(orderId, amount);
    }
}</code></pre>
                </div>
            </div>
            
            <div>
                <h3 class="text-2xl font-bold mb-4 text-primary flex items-center">
                    <i class="fas fa-star mr-3"></i> 5.3 架构优势
                </h3>
                <div class="grid md:grid-cols-3 gap-4">
                    <div class="bg-blue-50 p-4 rounded-md border-l-4 border-blue-500">
                        <h4 class="font-bold mb-2">解耦支付渠道</h4>
                        <p>新增支付方式不影响现有逻辑</p>
                    </div>
                    <div class="bg-green-50 p-4 rounded-md border-l-4 border-green-500">
                        <h4 class="font-bold mb-2">统一处理流程</h4>
                        <p>标准化支付异常和日志记录</p>
                    </div>
                    <div class="bg-purple-50 p-4 rounded-md border-l-4 border-purple-500">
                        <h4 class="font-bold mb-2">灵活路由</h4>
                        <p>动态调整支付渠道优先级</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Section 6 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 border-b-2 border-primary pb-2">六、实战案例三：智能物流系统</h2>
            
            <div class="mb-8">
                <h3 class="text-2xl font-bold mb-4 text-primary flex items-center">
                    <i class="fas fa-shipping-fast mr-3"></i> 6.1 业务挑战
                </h3>
                <ul class="list-disc pl-6 space-y-2">
                    <li>多运输方式（陆运/空运/海运）</li>
                    <li>实时路径优化</li>
                    <li>运费动态计算</li>
                </ul>
            </div>
            
            <div class="mb-8">
                <h3 class="text-2xl font-bold mb-4 text-primary flex items-center">
                    <i class="fas fa-cogs mr-3"></i> 6.2 精妙架构设计
                </h3>
                <div class="code-block text-gray-200 p-4 rounded-md mb-4 overflow-x-auto">
                    <pre><code>// 工厂方法模式创建运输方式
public abstract class LogisticsFactory {
    public abstract Transport createTransport();
}

public class AirLogistics extends LogisticsFactory {
    public Transport createTransport() {
        return new Airplane();
    }
}

// 观察者模式实现状态通知
public class ShipmentTracker implements Observable {
    private List<Observer> observers = new ArrayList<>();
    
    public void addObserver(Observer o) {
        observers.add(o);
    }
    
    public void notifyObservers(String status) {
        observers.forEach(o -> o.update(status));
    }
}</code></pre>
                </div>
            </div>
            
            <div>
                <h3 class="text-2xl font-bold mb-4 text-primary flex items-center">
                    <i class="fas fa-star mr-3"></i> 6.3 架构优势
                </h3>
                <div class="grid md:grid-cols-3 gap-4">
                    <div class="bg-blue-50 p-4 rounded-md border-l-4 border-blue-500">
                        <h4 class="font-bold mb-2">灵活扩展运输方式</h4>
                        <p>新增运输方式不影响核心逻辑</p>
                    </div>
                    <div class="bg-green-50 p-4 rounded-md border-l-4 border-green-500">
                        <h4 class="font-bold mb-2">实时状态同步</h4>
                        <p>多方及时获取物流信息</p>
                    </div>
                    <div class="bg-purple-50 p-4 rounded-md border-l-4 border-purple-500">
                        <h4 class="font-bold mb-2">动态策略调整</h4>
                        <p>根据环境变化优化运输路径</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Section 7 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 border-b-2 border-primary pb-2">七、架构设计：平衡的艺术</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-10">
                <div class="card bg-white p-6 rounded-lg shadow-md">
                    <h3 class="text-2xl font-bold mb-4 text-primary">1. 抽象与具体的平衡</h3>
                    <ul class="list-disc pl-6 space-y-2">
                        <li>过度抽象导致理解成本上升</li>
                        <li>过于具体丧失扩展能力</li>
                    </ul>
                </div>
                
                <div class="card bg-white p-6 rounded-lg shadow-md">
                    <h3 class="text-2xl font-bold mb-4 text-primary">2. 继承与组合的抉择</h3>
                    <div class="code-block text-gray-200 p-4 rounded-md mb-4 overflow-x-auto">
                        <pre><code>// 组合优于继承的典型场景
public class AdvancedLogger {
    private SimpleLogger logger; // 组合基础功能
    public void logWithTimestamp(String message) {
        logger.log(LocalDateTime.now() + " " + message);
    }
}</code></pre>
                    </div>
                </div>
            </div>

            <div class="card bg-white p-6 rounded-lg shadow-md">
                <h3 class="text-2xl font-bold mb-4 text-primary">3. 模式与反模式的界限</h3>
                <div class="grid md:grid-cols-2 gap-4">
                    <div>
                        <h4 class="font-bold mb-2">好的模式</h4>
                        <ul class="list-disc pl-6 space-y-1">
                            <li>Singleton模式</li>
                            <li>Factory模式</li>
                        </ul>
                    </div>
                    <div>
                        <h4 class="font-bold mb-2">需警惕的反模式</h4>
                        <ul class="list-disc pl-6 space-y-1">
                            <li>全局变量滥用</li>
                            <li>过度工程</li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="footer text-gray-200 py-8 px-4">
        <div class="max-w-6xl mx-auto">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold">技术小馆</h3>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="hover:text-blue-300 transition-colors">
                        <i class="fas fa-globe mr-2"></i> http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            mermaid.initialize({
                startOnLoad: true,
                theme: 'default',
                flowchart: {
                    useMaxWidth: true,
                    htmlLabels: true
                }
            });
        });
    </script>
</body>
</html>